home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol399 / olref.arc / CSAMPLE.ORD < prev    next >
Encoding:
Text File  |  1987-11-18  |  14.4 KB  |  191 lines

  1. @@creat - create unbuffered io file.
  2. $$       █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
  3.        █ THIS IS A SAMPLE OF THE SOFTEK C LANGUAGE REFERENCE FILE  █
  4.        █ The complete C Language On-Line Reference files will soon █
  5.        █   be available for purchase from SofTek for only $9.95    █
  6.        █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
  7.  
  8. ╔═════════════════════════════════════════════════════════════════════════════╗
  9. ║ NAME: creat                                                                 ║
  10. ╟─────────────────────────────────────────────────────────────────────────────╢
  11. ║ DESCRIPTION: create a file and open for unbuffered i/o.                     ║
  12. ╟─────────────────────────────────────────────────────────────────────────────╢
  13. ║ USAGE: creat(name,pmode)                                                    ║
  14. ║          char *name;                                                        ║
  15. ║          int pmode;                                                         ║
  16. ╟─────────────────────────────────────────────────────────────────────────────╢
  17. ║ NOTES: creat() creates a file and opens it for unbuffered, write-only       ║
  18. ║        access.  If the file already exists, it is truncated so that         ║
  19. ║        nothing is in it.  creat() returns as its value an integer called    ║
  20. ║        a 'file descriptor'.  Whenever a call is made to one of the          ║
  21. ║        unbuffered i/o functions to access the file, its file descriptor     ║
  22. ║        must be included in the functions parameters.                        ║
  23. ║        NAME is a pointer to a character string which is the name of the     ║
  24. ║        device or file to be opened.                                         ║
  25. ║        PMODE is optional. If specified, it is ignored.  It should be        ║
  26. ║        included, however, for programs for which UNIX compatibility         ║
  27. ║        is required, since the UNIX creat() function requires it.  In        ║
  28. ║        this case, PMODE should have the octal value 0666.                   ║
  29. ╟─────────────────────────────────────────────────────────────────────────────╢
  30. ║ ERROR INFO: If creat() fails, it returns -1 as its value and sets a code    ║
  31. ║             in the global integer ERRNO.                                    ║
  32. ╟─────────────────────────────────────────────────────────────────────────────╢
  33. ║ LIBRARY: x.lib                                                              ║
  34. ║                                                                             ║
  35. ╚═════════════════════════════════════════════════════════════════════════════╝
  36. @@exp - compute exponential.
  37. $$       █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
  38.        █ THIS IS A SAMPLE OF THE SOFTEK C LANGUAGE REFERENCE FILE  █
  39.        █ The complete C Language On-Line Reference files will soon █
  40.        █   be available for purchase from SofTek for only $9.95    █
  41.        █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
  42.  
  43. ╔═════════════════════════════════════════════════════════════════════════════╗
  44. ║ NAME: exp                                                                   ║
  45. ╟─────────────────────────────────────────────────────────────────────────────╢
  46. ║ DESCRIPTION: compute exponential.                                           ║
  47. ╟─────────────────────────────────────────────────────────────────────────────╢
  48. ║ USAGE: double exp(x)                                                        ║
  49. ║          double x;                                                          ║
  50. ╟─────────────────────────────────────────────────────────────────────────────╢
  51. ║ NOTES: none.                                                                ║
  52. ╟─────────────────────────────────────────────────────────────────────────────╢
  53. ║ ERROR INFO: If unsuccessful, the function sets an error code in the global  ║
  54. ║             integer ERRNO and returns an arbitrary value; otherwise         ║
  55. ║             it returns the computed value without modifying ERRNO.  The     ║
  56. ║             symbolic values which the function can place in ERRNO are       ║
  57. ║             EDOM, signifying that the argument was invalid, and ERANGE,     ║
  58. ║             meaning that the value of the function couldn't be computed.    ║
  59. ║             The codes are defined in the file 'errno.h'.                    ║
  60. ║             The following table lists the errorcodes that can be returned,  ║
  61. ║             the function value for that error, and the meaning of the       ║
  62. ║             error.  The symbolic values are defined in the file 'math.h'.   ║
  63. ║                                                                             ║
  64. ║             ****************************************************************║
  65. ║             * function   |    error   |    f(x)     |       meaning        *║
  66. ║             *============|============|=============|======================*║
  67. ║             *  exp       |  ERANGE    |   HUGE      | x > LOGHUGE          *║
  68. ║             *  exp       |  ERANGE    |   0.0       | x < LOGTINY          *║
  69. ║             ****************************************************************║
  70. ╟─────────────────────────────────────────────────────────────────────────────╢
  71. ║ LIBRARY: x.lib                                                              ║
  72. ║                                                                             ║
  73. ╚═════════════════════════════════════════════════════════════════════════════╝
  74. @@fopen - open buffered io stream.
  75. $$       █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
  76.        █ THIS IS A SAMPLE OF THE SOFTEK C LANGUAGE REFERENCE FILE  █
  77.        █ The complete C Language On-Line Reference files will soon █
  78.        █   be available for purchase from SofTek for only $9.95    █
  79.        █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
  80.  
  81. ╔═════════════════════════════════════════════════════════════════════════════╗
  82. ║ NAME: fopen                                                                 ║
  83. ╟─────────────────────────────────────────────────────────────────────────────╢
  84. ║ DESCRIPTION: open i/o stream.                                               ║
  85. ╟─────────────────────────────────────────────────────────────────────────────╢
  86. ║ USAGE: FILE *fopen(filename, mode)                                          ║
  87. ║          char *filename, *mode;                                             ║
  88. ╟─────────────────────────────────────────────────────────────────────────────╢
  89. ║ NOTES: fopen() opens the device or file specified by the FILENAME parameter ║
  90. ║        for access by the standard i/o functions specified by the MODE       ║
  91. ║        parameter.  The open file or device is called a 'stream'.            ║
  92. ║        If the file or device is successfully opened, the function returns   ║
  93. ║        a file pointer to a structure of type file.  This file pointer       ║
  94. ║        will be used for future accesses to the open stream.                 ║
  95. ║        MODE points to a character string which specifies how the user's     ║
  96. ║        program intends to access the stream.  The choices are as follows:   ║
  97. ║        r - Open for reading only.  If a file is opened, it is positioned    ║
  98. ║            at the first character in it.  If the file or device does not    ║
  99. ║            exist, NULL is returned.                                         ║
  100. ║        w - Open for writing only.  If a file is opened which already        ║
  101. ║            exist, it is truncated to zero length.  If the file does         ║
  102. ║            not exist, it is created.                                        ║
  103. ║        a - Open for appending.  The calling program is granted write only   ║
  104. ║            access to the stream.  The current file position is the          ║
  105. ║            character after the last character in the file.  If the file     ║
  106. ║            does not exist, it is created.                                   ║
  107. ║        x - Open for writing.  The file must NOT previously exist.  This     ║
  108. ║            option is NOT supported by UNIX.                                 ║
  109. ║        r+ - Open for reading and writing.  Same as 'r', but the stream      ║
  110. ║             may also be written to.                                         ║
  111. ║        w+ - Open for writing and reading.  Same as 'w', but the stream      ║
  112. ║             may also be read; different from 'r+' in the creation of a      ║
  113. ║             new file and loss of any previous one.                          ║
  114. ║        a+ - Open for appending and reading.  Same as 'a' but the stream     ║
  115. ║             may also be read;  different from 'r+' in file positioning      ║
  116. ║             and file creation.                                              ║
  117. ║        x+ - Open for writing and reading.  Same as 'x' but the file can     ║
  118. ║             also be read.                                                   ║
  119. ║        On systems which don't keep track of the last character in a file    ║
  120. ║        (such as CP/M and Apple DOS), not all files can be correctly         ║
  121. ║        positioned when opened in append mode.                               ║
  122. ║        FILENAME is a pointer to a character string which is the name        ║
  123. ║        of the device or file to be opened.                                  ║
  124. ║        The header 'stdio.h' must be included before this function can       ║
  125. ║        be used.                                                             ║
  126. ║        EXAMPLE:                                                             ║
  127. ║          if ((fp = fopen(*fname, *fmode)) == NULL)                          ║
  128. ║            printf("unable to open specified file");                         ║
  129. ║          else                                                               ║
  130. ║            printf("file is open");                                          ║
  131. ╟─────────────────────────────────────────────────────────────────────────────╢
  132. ║ ERROR INFO: If the file or device cannot be opened, NULL is returned and    ║
  133. ║             an error code is set in the global integer ERRNO.               ║
  134. ╟─────────────────────────────────────────────────────────────────────────────╢
  135. ║ LIBRARY: x.lib                                                              ║
  136. ║                                                                             ║
  137. ╚═════════════════════════════════════════════════════════════════════════════╝
  138. @@fread - read binary data from a buffered io stream.
  139. $$       █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
  140.        █ THIS IS A SAMPLE OF THE SOFTEK C LANGUAGE REFERENCE FILE  █
  141.        █ The complete C Language On-Line Reference files will soon █
  142.        █   be available for purchase from SofTek for only $9.95    █
  143.        █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
  144.  
  145. ╔═════════════════════════════════════════════════════════════════════════════╗
  146. ║ NAME: fread                                                                 ║
  147. ╟─────────────────────────────────────────────────────────────────────────────╢
  148. ║ DESCRIPTION: read binary data from an i/o stream.                           ║
  149. ╟─────────────────────────────────────────────────────────────────────────────╢
  150. ║ USAGE: int fread(buffer, size, count, stream)                               ║
  151. ║          char *buffer;                                                      ║
  152. ║          int size, count;                                                   ║
  153. ║          FILE *stream;                                                      ║
  154. ╟─────────────────────────────────────────────────────────────────────────────╢
  155. ║ NOTES: fread() performs a buffered input operation to the open stream       ║
  156. ║        specified by the parameter STREAM.                                   ║
  157. ║        BUFFER is the address of the user's buffer which will be used        ║
  158. ║        for the operation.                                                   ║
  159. ║        The function reads COUNT items, each containing SIZE bytes, from     ║
  160. ║        the stream.                                                          ║
  161. ║        The function performs i/o using the function getc(), thus no         ║
  162. ║        translations occur on the data being transferred.                    ║
  163. ║        The function returns as its value the number of items actually       ║
  164. ║        read.                                                                ║
  165. ║        The header 'stdio.h' must be included before use of this function.   ║
  166. ║        EXAMPLE                                                              ║
  167. ║          This is the code for reading ten integers from file 1 and writing  ║
  168. ║          then again to file 2.  It includes a simple check that there are   ║
  169. ║          enough two-byte items in the first file:                           ║
  170. ║          #include "stdio.h"                                                 ║
  171. ║          main()                                                             ║
  172. ║          {                                                                  ║
  173. ║            FILE *fp1, *fp2, *fopen();                                       ║
  174. ║            char *buf;                                                       ║
  175. ║            int size = 2, count = 10;                                        ║
  176. ║                                                                             ║
  177. ║            fp1 = fopen("file1","r");                                        ║
  178. ║            fp2 = fopen("file2","w");                                        ║
  179. ║            if (fread(buf, size, count, fp1) != count)                       ║
  180. ║               printf("Not enough integers in file 1\n");                    ║
  181. ║            fwrite(buf, size, count, fp2);                                   ║
  182. ║          }                                                                  ║
  183. ╟─────────────────────────────────────────────────────────────────────────────╢
  184. ║ ERROR INFO: fread() returns 0 upon end of file or error.  The functions     ║
  185. ║             feof() and ferror() can be used to distinguish between          ║
  186. ║             the two.  In case of error, the global integer ERRNO            ║
  187. ║             contains a code defining the error.                             ║
  188. ╟─────────────────────────────────────────────────────────────────────────────╢
  189. ║ LIBRARY: x.lib                                                              ║
  190. ╚═════════════════════════════════════════════════════════════════════════════╝
  191.